package Repository;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import model.Contract;
import model.ContractRule;
import model.Imported;
import model.Prepared;

public class ContractRepository extends Repository{
	
	private static HashMap<Long,Contract> contractMap = new HashMap<Long,Contract>();

	static{
		ContractRule cr = new ContractRule();
		//500000
		Contract c = new Contract();
		c.setDescription("Dell Laptop");
		c.setBillingAddress("San Jose");
		c.setShippingAddress("Fremont");
		c.setCurrentState(new Prepared());
		c.setCost(75000);
		c.setMaxLevel(cr.getMaxLevel(c));
		c.setStartDate(new Date(2010, 0, 01));
		c.setEndDate(new Date(2010, 1, 01));
		c.setSmsObjId(10);		
		c.setManagedByUser(UserRepository.getSalesRep("San Jose"));
		c.setNextApprover(1);

		contractMap.put(new Long(10), c);
		
		c = new Contract();
		c.setDescription("Dell Laptop");
		c.setBillingAddress("New York");
		c.setShippingAddress("San Jose");
		c.setCurrentState(new Prepared());
		c.setCost(15000);
		c.setMaxLevel(cr.getMaxLevel(c));
		c.setStartDate(new Date(2010, 0, 01));
		c.setEndDate(new Date(2010, 4, 01));
		c.setSmsObjId(11);
		c.setManagedByUser(UserRepository.getSalesRep("San Jose"));
		c.setNextApprover(1);
		contractMap.put(new Long(11), c);
	}
	
	public Object retrieve(Long id) {
		/*if (smsobjType.equals(SMSConstants.OPPORTUNITY))
		{
			if(Type.equals("Qualified"))
			{
				return Opportunity.get(information.LeadType.equals("Qualified"));
			}
			else if(Type.equals("Prepared"))
			{
				return Opportunity.get(information.LeadType.equals("Prepared"));	
			}
			else if(Type.equals("ProduceQuoted"))
			{
			return Opportunity.get(information.LeadType.equals("ProduceQuoted"));
		
			}
			else if(Type.equals("ApproveQuoted"))
			{
			return Opportunity.get(information.LeadType.equals("ApproveQuoted"));
		
			}
		}	*/
		
		return contractMap.get(id);
	}
	
	
	public void delete(Long id) {
		
	}
	
	public void insert(Long id,Object obj) {
		contractMap.put(id, (Contract)obj);
				
	}
	
	public void update(Long id, Object updatedObj) {
		contractMap.remove(id);
		contractMap.put(id, (Contract)updatedObj);	
	}


	@Override
	public Object retrieve(String objectType, String ruleType) {
		// TODO Auto-generated method stub
		return null;
	}


	
	public List retrieve(String State) {
		List list =new ArrayList();
		Collection<Contract> c = contractMap.values();
		
		
			for(Contract contract : c )
			{	
				if(contract.getCurrentState().getStateName().equalsIgnoreCase(State))
				{
					list.add(contract);
				}				
			}
			
	return list;
	}


	@Override
	public boolean find(String objName) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public Collection retrieveAll() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
